home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / hsv_to_rgb.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  97 lines

  1. ; $Id: hsv_to_rgb.pro,v 1.3 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1989-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. pro hsv_to_rgb, h, s, v, red, green, blue
  7. ;+
  8. ; NAME:
  9. ;    HSV_TO_RGB
  10. ;
  11. ; PURPOSE:
  12. ;    Convert from the HSV (Hue, Saturation, Value) color system to
  13. ;    the RGB (Red, Green, Blue) color system.
  14. ;
  15. ; CATEGORY:
  16. ;    Graphics, color systems.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    HSV_TO_RGB, H, S, V, Red, Green, Blue
  20. ;
  21. ; INPUTS:
  22. ;    H:    The hue variable.  This value may be either vector or scalar.
  23. ;        Values for hue range from 0 to 360.  H is 0 if S (saturation) 
  24. ;        is 0.0.
  25. ;
  26. ;    S:    The saturation variable.  This variable should be the same 
  27. ;        size as H.  Valid values range from 0 to 1.
  28. ;
  29. ;    V:    The value variable.  This variable should be the same size
  30. ;        as H.  Valid values range from 0 to 1.
  31. ;
  32. ; KEYWORD PARAMETERS:
  33. ;    None.
  34. ;
  35. ; OUTPUTS:
  36. ;    Red:    The returned red color value(s). This returned variable has 
  37. ;        the same size as H.  RGB values are short integers in the
  38. ;        range 0 to 255.
  39. ;
  40. ;    Green:    The green color value(s).
  41. ;  
  42. ;    Blue:    The blue color value(s).
  43. ;
  44. ; COMMON BLOCKS:
  45. ;    None.
  46. ;
  47. ; SIDE EFFECTS:
  48. ;    None.
  49. ;
  50. ; RESTRICTIONS:
  51. ;    H must be in the range 0 to 360.  S and V must be in the range
  52. ;    0 to 1.0.
  53. ;
  54. ; PROCEDURE:
  55. ;    Taken from Foley & Van Dam, Fundamentals of Interactive Computer
  56. ;    Graphics, 1982, page 616.
  57. ;
  58. ; MODIFICATION HISTORY:
  59. ;    DMS, Aug, 1989.
  60. ;-
  61. on_error,2                      ;Return to caller if an error occurs
  62. n = n_elements(h)
  63. red = intarr(n) & green = intarr(n) & blue = intarr(n)
  64. hh = [h]        ;Make into vectors
  65. ss = [s]
  66. vv = reform([v], n)        ;Must be 1D
  67. s0 = where(ss eq 0.0, count)
  68. if count ne 0 then begin    ;Monochromatic case
  69.     q = v(s0) * 255.    ;gray value
  70.     red(s0) = q
  71.     green(s0) = q
  72.     blue(s0) = q
  73.     endif
  74. s0 = where(hh eq 360., count)
  75. if count ne 0 then hh(s0) = 0.0
  76.  
  77. s0 = where(ss ne 0.0, count)
  78. if count ne 0 then begin
  79.     hh = float(hh) / 60.
  80.     hi = fix(hh)        ;floor
  81.     f = hh - hi        ;remainder
  82.     p = vv * (1.0 -ss)
  83.     q = vv * (1.0-ss*f)
  84.     t = vv*(1.0-(ss*(1.-f)))
  85.  
  86.     ;       0   1   2   3
  87.     tmp = [[p],[q],[t],[vv]] * 255.
  88.     rindex = [3,1,0,0,2,3]
  89.     gindex = [2,3,3,1,0,0]
  90.     bindex = [0,0,2,3,3,1]
  91.     hi=hi(s0)
  92.     red(s0) = tmp(s0,rindex(hi))
  93.     green(s0) = tmp(s0,gindex(hi))
  94.     blue(s0) = tmp(s0,bindex(hi))
  95.     endif
  96. end
  97.